@echo off
setlocal

rem 指定要关闭的端口
set PORT=9900

rem 查找占用指定端口的进程ID
for /f "tokens=5" %%a in ('netstat -aon ^| findstr :%PORT% ^| findstr LISTENING') do (
    set PID=%%a
)

rem 检查是否找到进程ID
if "%PID%"=="" (
    echo Port %PORT% is not in use.
) else (
    rem 杀死占用端口的进程
    taskkill /PID %PID% /F
    echo Process %PID% that was using port %PORT% has been terminated.
)

endlocal
